package hasthi.container.notifier;

import static hasthi.common.constants.HasthiConstants.UNSPECIFIED_EPR;
import hasthi.common.HasthiException;
import hasthi.common.constants.WSDMConstants;
import hasthi.wsdm.ManagableResource;
import hasthi.wsdm.ManagementAgentContext;
import hasthi.wsrf.faults.UpdateResourcePropertiesRequestFailedFault;

public class ManageableResourceNotifier extends XSULBasedNotifier{
    private int errorCount = 0; 
    private ManagableResource resource;
    public ManageableResourceNotifier(ManagementAgentContext agentContext,ManagableResource resource,String eventSink) throws HasthiException {
        super(eventSink, agentContext);
        this.resource = resource;
    }
    @Override
    public boolean sendingEventFalied(Exception e) {
        errorCount++;
        if(errorCount > 3){
            try {
                resource.updateResourceProperties(WSDMConstants.MANAGMENT_EVNET_SINK_PARAM,UNSPECIFIED_EPR);
                return super.sendingEventFalied(e);
            } catch (UpdateResourcePropertiesRequestFailedFault e1) {
                log.warn("Sending event failed "+e1.getMessage());
                return true;
            }
        }else{
            return false;
        }
    }
}
